<?php
/**
 * Created by PhpStorm.
 * User: hanbin
 * Date: 17/4/17
 * Time: 下午4:55
 */

namespace App\Server;

use Illuminate\Support\Facades\DB;

/**
 * 收藏
 * Class CollectionModel
 * @package App\Server
 */
class CollectionModel extends BaseModel
{
    protected $table = 'collection';

    /**
     * 收藏列表
     * @param int $pagesize
     * @param string $field
     * @param int $lastid
     * @param array $so
     * @return mixed
     */
    public static function getListLikeMemberList($pagesize = 10, $field = '', $lastid = 1, $so = [])
    {
        if ($so) {
            $result = DB::table('collection')->join('part_time_job', 'collection.p_id', '=', 'part_time_job.id')->where($so)->select('part_time_job.*')->orderBy('part_time_job.id', 'desc')->paginate($pagesize);
        } else {
            $result = DB::table('collection')->join('part_time_job', 'collection.p_id', '=', 'part_time_job.id')->select('part_time_job.*')->orderBy('part_time_job.id', 'desc')->paginate($pagesize);
        }
        $_result = [];
        if ($result) {
            $data = [];
            foreach ($result as $k => $v) {
                $v = json_decode(json_encode($v),true);
                $data[] = $v;
            }
            $_result['data'] = $data;
            $_result['total'] = $result->total();
            $_result['count'] = $result->count();
            $_result['currentPage'] = $result->currentPage();
            $_result['firstItem'] = $result->firstItem();
            $_result['lastItem'] = $result->lastItem();
            $_result['lastPage'] = $result->lastPage();
            $_result['perPage'] = $result->perPage();
            $_result['pagesize'] = $result->perPage();
        }
        return $_result;
    }

}